DBF<>INTERBASE

Otázka od: Dalibor

28. 11. 2002 10:01

Ahoj,
mam DBF FOXPRO(BDE) a tabulku v Interbase databazi, ktere maji
shodnou strukturu. Muzete mi poradit nejake inteligentni reseni,
prenaseni dat Z DBF na Interbase a opacne.
Potrebuji to udelat programove.
Dekuji (D5)

Odpovedá: Jan Tungli

28. 11. 2002 10:19

komponenta BachMove alebo Borland Datapump

   || -----Original Message-----
   || From: Dalibor [mailto:dalibor@torola.cz]
   || Sent: Thursday, November 28, 2002 9:40 AM
   || To: delphi-l@clexpert.cz
   || Subject: DBF<>INTERBASE
   ||
   ||
   || Ahoj,
   || mam DBF FOXPRO(BDE) a tabulku v Interbase databazi, ktere maji
   || shodnou strukturu. Muzete mi poradit nejake inteligentni reseni,
   || prenaseni dat Z DBF na Interbase a opacne.
   || Potrebuji to udelat programove.
   || Dekuji (D5)
   ||

Odpovedá: Petr Palicka

28. 11. 2002 12:37

ahoj,

  pokud se chces vyhnout BDE, tak treba TDBF
{v zavorkach je zruseni a vytvoreni nove prazdne tabulky}
funguje to z FB do DBF obracene to snad zvladnes am  :

procedure TFMain.mmExportDBFClick(Sender: TObject);
var
  q: TIBQuery;
  d: TDBF;
  i, j: Integer;
  f: TField;
begin
  Screen.Cursor:=crSQLWait;
  q:=TIBQuery.Create(FMain);
  d:=TDBF.Create(FMain);
  try
    q.Database:=FDM.IBAGSKOT;
    q.Transaction:=FDM.IBT;
    d.FilePath:=ExtractFileDir(Application.ExeName);
    d.OpenMode:=omAutoCreate;
    d.Storage:=stoFile;
    d.TableName:='SKOT.DBF';
{
    if FileExists(d.FilePath+PathDelim+d.TableName) then
      DeleteFile(d.FilePath+PathDelim+d.TableName);
    d.FieldDefs.Clear;
    d.FieldDefs.Add('USZNZ', ftString, 2);
    d.FieldDefs.Add('USZN', ftString, 12);
    d.FieldDefs.Add('PLEMENO', ftString, 4);
    d.FieldDefs.Add('DATNAR', ftDate);
    d.FieldDefs.Add('POHLAVI', ftString, 1);
    d.FieldDefs.Add('MUSZNZ', ftString, 2);
    d.FieldDefs.Add('MUSZN', ftString, 12);
    d.FieldDefs.Add('MPLEMENO', ftString, 4);
    d.FieldDefs.Add('LB', ftString, 3);
    d.FieldDefs.Add('RB', ftString, 3);
    d.FieldDefs.Add('OMLB', ftString, 3);
    d.FieldDefs.Add('OMRB', ftString, 3);
    d.FieldDefs.Add('VYRAZENO', ftString, 1);
    d.FieldDefs.Add('DRUH', ftString, 1);
    d.FieldDefs.Add('HOSP', ftString, 1);
    d.FieldDefs.Add('SKOD', ftString, 2);
    d.FieldDefs.Add('DATPOR', ftDate);
    d.FieldDefs.Add('DATZM', ftDate);
    d.CreateTable;
}
    d.Open;
    d.First;
    while not d.eof do d.Delete;
    d.PackTable;
    q.SQL.Text:='select * from Skot';
    j:=d.FieldCount-1;
    q.Open;
    q.First;
    while not q.Eof do
      begin
        d.Append;
        for i:=0 to j do
          begin
            f:=q.FindField(d.Fields[i].FieldName);
            if Assigned(f) then
              d.Fields[i].Value:=f.Value
            else
              d.Fields[i].Value:=null;
// pro sychr, jinac by to slo volat natvrdo
// d.Fields[i].Value:=q.FindField(d.Fields[i].FieldName).Value;
          end;
        d.Post;
        q.Next;
      end;
    d.Close;
    q.Close;
    d.TableName:='POHZVR.DBF';
{
    if FileExists(d.FilePath+PathDelim+d.TableName) then
      DeleteFile(d.FilePath+PathDelim+d.TableName);
    d.FieldDefs.Clear;
    d.FieldDefs.Add('POHZVR', ftInteger);
    d.FieldDefs.Add('POHDAVKA', ftInteger);
    d.FieldDefs.Add('DAVKA', ftInteger);
    d.FieldDefs.Add('HOSP', ftString, 1);
    d.FieldDefs.Add('SKOD', ftString, 2);
    d.FieldDefs.Add('USZNZ', ftString, 2);
    d.FieldDefs.Add('USZN', ftString, 12);
    d.FieldDefs.Add('POHYB', ftString, 2);
    d.FieldDefs.Add('PKODD', ftString, 8);
    d.FieldDefs.Add('SKODD', ftString, 2);
    d.FieldDefs.Add('ZEME', ftString, 3);
    d.FieldDefs.Add('DATUM', ftDate);
    d.FieldDefs.Add('POZN', ftString, 40);
    d.FieldDefs.Add('ZDKOD', ftString, 5);
    d.FieldDefs.Add('DATPOR', ftDate);
    d.FieldDefs.Add('DATZM', ftDate);
    d.CreateTable;
}
    d.Open;
    d.First;
    while not d.eof do d.Delete;
    d.PackTable;
    q.SQL.Text:='select * from PohZvr';
    j:=d.FieldCount-1;
    q.Open;
    q.First;
    while not q.Eof do
      begin
        d.Append;
        for i:=0 to j do
          begin
            f:=q.FindField(d.Fields[i].FieldName);
            if Assigned(f) then
              d.Fields[i].Value:=f.Value
            else
              d.Fields[i].Value:=null;
          end;
        d.Post;
        q.Next;
      end;
    d.Close;
    q.Close;
    d.TableName:='CISPOHYB.DBF';
{
    if FileExists(d.FilePath+PathDelim+d.TableName) then
      DeleteFile(d.FilePath+PathDelim+d.TableName);
    d.FieldDefs.Clear;
    d.FieldDefs.Add('POHYB', ftString, 2);
    d.FieldDefs.Add('PONAZEV', ftString, 90);
    d.FieldDefs.Add('PLUS', ftSmallint);
    d.FieldDefs.Add('HL', ftString, 1);
    d.CreateTable;
}
    d.Open;
    d.First;
    while not d.eof do d.Delete;
    d.PackTable;
    q.SQL.Text:='select * from CisPohyb';
    j:=d.FieldCount-1;
    q.Open;
    q.First;
    while not q.Eof do
      begin
        d.Append;
        for i:=0 to j do
          begin
            f:=q.FindField(d.Fields[i].FieldName);
            if Assigned(f) then
              d.Fields[i].Value:=f.Value
            else
              d.Fields[i].Value:=null;
          end;
        d.Post;
        q.Next;
      end;
    d.Close;
    q.Close;
  finally
    q.Free;
    d.Free;
    Screen.Cursor:=crDefault;
  end;
  Application.MessageBox('Export dat dokoncen.', 'HOTOVO',
    mb_applmodal+mb_iconinformation+mb_okcancel+mb_defbutton1);
end;